package cn.ransj.animation;

import cn.ransj.animation.util.AniConnector;
import cn.ransj.animation.util.AniConnectorInterface;
import cn.ransj.animation.util.AniCoonectorListener;
import cn.ransj.animation.util.AniUtil;
import cn.ransj.animation.util.ImageProvider;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class AnimationActivity extends Activity {
	
	private static final String TAG = AnimationActivity.class.getSimpleName();
	private ImageView m_tvText;
	private Button m_btnOk;
	private AniUtil mAniManager;
	private ImageProvider mImgProvider;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mAniManager = new AniUtil();
        mAniManager.init();
        mImgProvider = ImageProvider.getInstance();
        m_tvText = (ImageView) findViewById(R.id.main_textview);
        m_btnOk = (Button) findViewById(R.id.main_button);
        m_btnOk.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				show();
//				printImags();
			}
		});
    }
    
    private void show(){
    	m_tvText.setVisibility(View.VISIBLE);
    	AniConnectorInterface connector = mAniManager.random();
    	connector.setAniConnectorListener(new AniCoonectorListener() {
			
			public void onAnimationStart(AniConnector animation) {
				
			}
			
			public void onAnimationEnd(AniConnector animation) {
				Bitmap img = mImgProvider.nextImg();
				if(img != null){
					AniConnectorInterface connector = mAniManager.random();
					m_tvText.setImageBitmap(img);
					connector.setAniConnectorListener(this);
					connector.start(m_tvText);
				}
			}
		});
    	m_tvText.setImageBitmap(mImgProvider.initProvider(this));
    	connector.start(m_tvText);
    }
}